* de-duplicate format and filter vector display code.
* consolidate release of argument memory in vecs, filter_vecs.
return {};
}
-void FilterVecs::free_filter_vec(fltinfo_t& filter)
+void FilterVecs::free_filter_vec(Filter* flt)
{
- QVector<arglist_t>* args = filter->get_args();
-
- if (args && !args->isEmpty()) {
- assert(args->isDetached());
- for (auto& arg : *args) {
- if (arg.argvalptr) {
- xfree(arg.argvalptr);
- arg.argvalptr = *arg.argval = nullptr;
- }
- }
- }
+ Vecs::free_options(flt->get_args());
}
void FilterVecs::init_filter_vec(Filter* flt)
void FilterVecs::exit_filter_vec(Filter* flt)
{
(flt->exit)();
- QVector<arglist_t>* args = flt->get_args();
- if (args && !args->isEmpty()) {
- assert(args->isDetached());
- for (auto& arg : *args) {
- if (arg.argvalptr) {
- xfree(arg.argvalptr);
- *arg.argval = arg.argvalptr = nullptr;
- }
- }
- }
+ Vecs::free_options(flt->get_args());
}
void FilterVecs::exit_filter_vecs()
* Display the available formats in a format that's easy for humans to
* parse for help on available command line options.
*/
-void FilterVecs::disp_filter_vecs() const
-{
- for (const auto& vec : d_ptr_->filter_vec_list) {
- Filter* flt = (vec.factory != nullptr)? vec.factory() : vec.vec;
- printf(" %-20.20s %-50.50s\n",
- qPrintable(vec.name), qPrintable(vec.desc));
- const QVector<arglist_t>* args = flt->get_args();
- if (args) {
- for (const auto& arg : *args) {
- if (!(arg.argtype & ARGTYPE_HIDDEN)) {
- printf(" %-18.18s %-.50s %s\n",
- qPrintable(arg.argstring), qPrintable(arg.helpstring),
- (arg.argtype & ARGTYPE_REQUIRED) ? "(required)" : "");
- }
- }
- }
- if (vec.factory != nullptr) {
- delete flt;
- }
- }
-}
-
void FilterVecs::disp_filter_vec(const QString& vecname) const
{
for (const auto& vec : d_ptr_->filter_vec_list) {
- if (vecname.compare(vec.name, Qt::CaseInsensitive) != 0) {
+ /*
+ * Display info for all filter is vecname is empty,
+ * otherwise just display info for the matching filter.
+ */
+ if (!vecname.isEmpty() && (vecname.compare(vec.name, Qt::CaseInsensitive) != 0)) {
continue;
}
Filter* flt = (vec.factory != nullptr)? vec.factory() : vec.vec;
static void prepare_filter(const fltinfo_t& fltdata);
fltinfo_t find_filter_vec(const QString& fltargstring);
- static void free_filter_vec(fltinfo_t& filter);
+ static void free_filter_vec(Filter* flt);
static void init_filter_vec(Filter* flt);
void init_filter_vecs();
static void exit_filter_vec(Filter* flt);
void exit_filter_vecs();
- void disp_filter_vecs() const;
- void disp_filter_vec(const QString& vecname) const;
+ void disp_filter_vec(const QString& vecname = QString()) const;
void disp_filters(int version) const;
bool validate_filters() const;
}
static void
-usage(const char* pname, int shorter)
+usage(const char* pname, bool verbose)
{
printf("GPSBabel Version %s. https://www.gpsbabel.org\n\n",
gpsbabel_version);
, pname
, global_opts.debug_level
);
- if (shorter) {
+ if (!verbose) {
printf("\n\n[Press enter]");
fgetc(stdin);
} else {
printf("File Types (-i and -o options):\n");
- Vecs::Instance().disp_vecs();
+ Vecs::Instance().disp_vec();
printf("\nSupported data filters:\n");
- FilterVecs::Instance().disp_filter_vecs();
+ FilterVecs::Instance().disp_filter_vec();
}
}
QStringList qargs = QCoreApplication::arguments();
if (qargs.size() < 2) {
- usage(prog_name,1);
+ usage(prog_name, false);
return 0;
}
if (argn < qargs.size()-1) {
spec_usage(qargs.at(argn+1));
} else {
- usage(prog_name,0);
+ usage(prog_name, true);
}
return 0;
}
filter->init();
filter->process();
filter->deinit();
- FilterVecs::free_filter_vec(filter);
+ FilterVecs::free_filter_vec(filter.flt);
FilterVecs::exit_filter_vec(filter.flt);
delete filter.flt;
filter->init();
filter->process();
filter->deinit();
- FilterVecs::free_filter_vec(filter);
+ FilterVecs::free_filter_vec(filter.flt);
}
} else {
fatal("Unknown filter '%s'\n",qPrintable(argument));
return 0;
case 'h':
case '?':
- usage(prog_name,0);
+ usage(prog_name, true);
return 0;
case 'p':
argument = FETCH_OPTARG;
}
} else if (!qargs.isEmpty()) {
- usage(prog_name,0);
+ usage(prog_name, true);
return 0;
}
if (!ovecs) {
(!val.isEmpty() && val.at(0).isDigit());
}
-void Vecs::exit_vec(Format* fmt)
+void Vecs::free_options(QVector<arglist_t>* args)
{
- (fmt->exit)();
- QVector<arglist_t>* args = fmt->get_args();
if (args && !args->isEmpty()) {
assert(args->isDetached());
for (auto& arg : *args) {
}
}
+void Vecs::exit_vec(Format* fmt)
+{
+ (fmt->exit)();
+ free_options(fmt->get_args());
+}
+
void Vecs::exit_vecs()
{
for (const auto& vec : d_ptr_->vec_list) {
return svp;
}
-#define VEC_FMT " %-20.20s %-.50s\n"
-
-void Vecs::disp_vecs() const
-{
- const auto svp = sort_and_unify_vecs();
- for (const auto& vec : svp) {
- if (vec.type == ff_type_internal) {
- continue;
- }
- printf(VEC_FMT, qPrintable(vec.name), qPrintable(vec.desc));
- const QVector<arginfo_t> args = vec.arginfo;
- for (const auto& arg : args) {
- if (!(arg.argtype & ARGTYPE_HIDDEN)) {
- printf(" %-18.18s %s%-.50s%s\n",
- qPrintable(arg.argstring),
- (arg.argtype & ARGTYPE_TYPEMASK) ==
- ARGTYPE_BOOL ? "(0/1) " : "",
- qPrintable(arg.helpstring),
- (arg.argtype & ARGTYPE_REQUIRED) ? " (required)" : "");
- }
- }
- }
-}
-
void Vecs::disp_vec(const QString& vecname) const
{
const auto svp = sort_and_unify_vecs();
for (const auto& vec : svp) {
- if (vecname.compare(vec.name, Qt::CaseInsensitive) != 0) {
+ /*
+ * Display info for all non-internal formats is vecname is empty,
+ * otherwise just display info for the matching format.
+ */
+ if (vecname.isEmpty()? (vec.type == ff_type_internal) :
+ (vecname.compare(vec.name, Qt::CaseInsensitive) != 0)) {
continue;
}
- printf(VEC_FMT, qPrintable(vec.name), qPrintable(vec.desc));
+ printf(" %-20.20s %-.50s\n", qPrintable(vec.name), qPrintable(vec.desc));
const QVector<arginfo_t> args = vec.arginfo;
for (const auto& arg : args) {
if (!(arg.argtype & ARGTYPE_HIDDEN)) {
static void init_vec(Format* fmt);
void init_vecs();
+ static void free_options(QVector<arglist_t>* args);
static void exit_vec(Format* fmt);
void exit_vecs();
static void assign_option(const QString& module, arglist_t* arg, const QString& val);
static QString get_option(const QStringList& options, const QString& argname);
static void prepare_format(const fmtinfo_t& data);
fmtinfo_t find_vec(const QString& fmtargstring);
- void disp_vecs() const;
- void disp_vec(const QString& vecname) const;
+ void disp_vec(const QString& vecname = QString()) const;
static const char* name_option(uint32_t type);
void disp_formats(int version) const;
static bool validate_args(const QString& name, const QVector<arglist_t>* args);